package com.wwwc.util.web;

import java.util.*;

public class JavaScript {
    public static StringBuffer openNewWindow(String url, int width, int height, int type) {
	StringBuffer sbf = new StringBuffer();
	sbf.append("\n\n<SCRIPT>");
	sbf.append("\n function popup() {");
	sbf.append("\n  var wd = window.open(\""+url+"\",\"\", \"height="+height+", width="+width+", alwaysRaised, menubar=");
	sbf.append(type+", resizable, scrollbars\");");
	sbf.append("\n }");
	sbf.append("\n popup();");
	sbf.append("\n</SCRIPT>\n");
	return sbf;
    }

    public static StringBuffer printPage(String content, int width, int height, int type) {
	StringBuffer sbf = new StringBuffer();
	if(content.indexOf("\"") != -1) {
	    content = content.replaceAll("\"","&quot;");
	}

	sbf.append("\n\n<SCRIPT>");
	sbf.append("\n function popup()");
	sbf.append("\n {");
	sbf.append("\n  var wd = window.open(\"\",\"\", \"height="+height+", width="+width+", alwaysRaised, menubar=");
	sbf.append(type+", resizable, scrollbars\");");
	String temp = null;

	StringTokenizer stk = new StringTokenizer(content);
	while(stk.hasMoreTokens()) {
	    temp = stk.nextToken();
	    sbf.append("\n  wd.document.write(\""+temp+" \");");
	}
	sbf.append("\n }");
	sbf.append("\n popup();");
	sbf.append("\n</SCRIPT>\n");
	return sbf;
    }
}


